package com.twu.biblioteca;

public enum Option {

    ADD_BOOK(1),
    VIEW_ALL_BOOKS(2, true),
    VIEW_ALL_MOVIES(3, true),
    RESERVE_BOOK(4),
    MEMBERSHIP_DETAILS(5, true),
    LOGIN(7, true),
    SHOW_MENU(8, true),
    EXIT(9, true),
    INVALID(10000000);

    private final String UNDERSCORE = "_";
    private final String SPACE = " ";
    private final String VALUE_NAME_SEPARATOR = ". ";

    private int value;
    private boolean publiclyVisible = false;

    Option(int value) {
        this.value = value;
    }

    Option(int value, boolean publiclyVisible) {
        this.value = value;
        this.publiclyVisible = publiclyVisible;
    }

    public static Option getOptionFromValue(int value) {

        for (Option currentValue : values()) {
            if (currentValue.value == value) {
                return currentValue;
            }
        }

        return Option.INVALID;
    }

    public String asMenuOption() {
        return value + VALUE_NAME_SEPARATOR + this.toString().replace(UNDERSCORE, SPACE);
    }

    public boolean isPubliclyVisible() {
        return publiclyVisible;
    }
}
